home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 November / PCWNOV08.iso / Software / Freeware / Mini Map Sidebar 0.3 / mini_map_sidebar-0.3.0-fx.xpi / chrome / content / rdfds.js < prev    next >
Encoding:
JavaScript  |  2008-02-20  |  18.8 KB  |  789 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is rdfds
  13.  *
  14.  * The Initial Developer of the Original Code is Neil Deakin
  15.  * Portions created by Neil Deakin are Copyright (C) 2002 Neil Deakin.
  16.  * All Rights Reserved.
  17.  *
  18.  * Contributor(s):
  19.  */
  20.  
  21. /* This is a library for easier access to RDF datasources and resources.
  22.  * It contains four objects, RDFDataSource, RDFNode, RDFLiteral. and
  23.  * RDFEnumerator.
  24.  *
  25.  * An RDF DataSource is a graph of nodes and literals. The constructor
  26.  * for RDFDataSource takes one argument, a URI of an RDF file to use.
  27.  * If the URI exists, the contents of the RDF file are loaded. If it
  28.  * does not exist, resources can be added to it and then written using
  29.  * this save method. If the URL argument is null, a blank datasource
  30.  * is created.
  31.  *
  32.  * This library is designed for convenience not for efficiency.
  33.  *
  34.  * The API is documented at:
  35.  *   http://www.xulplanet.com/tutorials/xultu/rdfds/
  36.  *
  37.  * Example:
  38.  *
  39.  * var ds=new RDFDataSource("file:///main/mozilla/mimtest.rdf");
  40.  * var node=ds.getNode("http://www.example.com/sample");
  41.  * var child=ds.getNode("http://www.example.com/child");
  42.  * child=node.addChild(child);
  43.  * child.addTarget("http://www.xulplanet.com/rdf/xpimaker#appname","Find Files");
  44.  * ds.save();
  45.  *
  46.  */
  47.  
  48. var RDFService = "@mozilla.org/rdf/rdf-service;1";
  49. RDFService = Components.classes[RDFService].getService();
  50. RDFService = RDFService.QueryInterface(Components.interfaces.nsIRDFService);
  51.  
  52. var RDFContainerUtilsService = "@mozilla.org/rdf/container-utils;1";
  53. RDFContainerUtilsService = Components.classes[RDFContainerUtilsService].getService();
  54. RDFContainerUtilsService = RDFContainerUtilsService.QueryInterface(Components.interfaces.nsIRDFContainerUtils);
  55.  
  56. /* RDFLoadObserver
  57.  *   this object is necessary to listen to RDF files being loaded. The Init
  58.  *   function should be called to initialize the callback when the RDF file is
  59.  *   loaded.
  60.  */
  61. function RDFLoadObserver(){}
  62.   
  63. RDFLoadObserver.prototype =
  64. {
  65.   callback: null,
  66.   callbackDataSource: null,
  67.  
  68.   Init: function(c,cDS){
  69.     this.callback=c;
  70.     this.callbackDataSource=cDS;
  71.   },
  72.  
  73.   QueryInterface: function(iid){
  74.     if (iid.equals(Components.interfaces.nsIRDFXMLSinkObserver)) return this;
  75.     else throw Components.results.NS_ERROR_NO_INTERFACE;
  76.   },
  77.  
  78.   onBeginLoad : function(sink){},
  79.   onInterrupt : function(sink){},
  80.   onResume : function(sink){},
  81.   onError : function(sink,status,msg){},
  82.  
  83.   onEndLoad : function(sink){
  84.     if (this.callback!=null) this.callback(this.callbackDataSource);
  85.   }
  86. };  
  87.  
  88. function RDFDataSource(uri,callbackFn)
  89. {
  90.   //alert(uri);
  91.   if (uri==null) this.datasource=null;
  92.   else this.load(uri,callbackFn);
  93. }
  94.  
  95. RDFDataSource.prototype.load=
  96.   function(uri,callbackFn)
  97. {
  98.   if (uri.indexOf(":") == -1){
  99.     var docurl=document.location.href;
  100.     if (document.location.pathname == null) uri=docurl+"/"+uri;
  101.     else uri=docurl.substring(0,docurl.lastIndexOf("/")+1)+uri;
  102.   }
  103.  
  104.   if (callbackFn == null){
  105.     this.datasource=RDFService.GetDataSourceBlocking(uri);
  106.   }
  107.   else {
  108.     this.datasource=RDFService.GetDataSource(uri);
  109.     var ds;
  110.     try {
  111.       ds=this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
  112.     }
  113.     catch (ex){
  114.       callbackFn(this);
  115.       return;
  116.     }
  117.     if (ds.loaded){
  118.       callbackFn(this);
  119.       return;
  120.     }
  121.  
  122.     var packObserver=new RDFLoadObserver();
  123.     packObserver.Init(callbackFn,this);
  124.  
  125.     var rawsource=this.datasource;
  126.     rawsource=rawsource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
  127.     rawsource.addXMLSinkObserver(packObserver);
  128.   }
  129. }
  130.  
  131. RDFDataSource.prototype.Init=
  132.   function (dsource)
  133. {
  134.   this.datasource=dsource;
  135. }
  136.  
  137. RDFDataSource.prototype.parseFromString=
  138.   function (str,baseUri)
  139. {
  140.   if (this.datasource==null) this.makeemptyds();
  141.   var ios=Components.classes["@mozilla.org/network/io-service;1"]
  142.                     .getService(Components.interfaces.nsIIOService);
  143.   baseUri=ios.newURI(baseUri,null,null);
  144.   var xmlParser=Components.classes["@mozilla.org/rdf/xml-parser;1"]
  145.                           .createInstance(Components.interfaces.nsIRDFXMLParser);
  146.   xmlParser.parseString(this.datasource,baseUri,str);
  147. }
  148.  
  149. RDFDataSource.prototype.serializeToString=
  150.   function ()
  151. {
  152.   var outputStream = {
  153.     data: "",
  154.     close : function(){},
  155.     flush : function(){},
  156.     write : function (buffer,count){
  157.       this.data += buffer;
  158.       return count;
  159.     },
  160.     writeFrom : function (stream,count){},
  161.     isNonBlocking: false
  162.   }
  163.   this.serializeToStream(outputStream);
  164.   return outputStream.data;
  165. }
  166.  
  167. RDFDataSource.prototype.serializeToStream=
  168.   function (outputStream)
  169. {
  170.   var ser=Components.classes["@mozilla.org/rdf/xml-serializer;1"]
  171.                     .createInstance(Components.interfaces.nsIRDFXMLSerializer);
  172.   ser.init(this.datasource);
  173.   ser.QueryInterface(Components.interfaces.nsIRDFXMLSource).Serialize(outputStream);
  174. }
  175.  
  176. RDFDataSource.prototype.makeemptyds=
  177.   function (uri)
  178. {
  179.   this.datasource=Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
  180.                             .createInstance(Components.interfaces.nsIRDFDataSource);
  181. }
  182.  
  183. RDFDataSource.prototype.getAllResources=
  184.   function ()
  185. {
  186.   if (this.datasource==null) return null;
  187.   return new RDFEnumerator(this.datasource.GetAllResources(),this.datasource);
  188. }
  189.  
  190. RDFDataSource.prototype.getRawDataSource=
  191.   function ()
  192. {
  193.   if (this.datasource==null) this.makeemptyds();
  194.   return this.datasource;
  195. }
  196.  
  197. RDFDataSource.prototype.getNode=
  198.   function (uri)
  199. {
  200.   if (this.datasource==null) this.makeemptyds();
  201.   var node=new RDFNode(uri,this);
  202.   return node;
  203. }
  204.  
  205. RDFDataSource.prototype.getAnonymousNode=
  206.   function ()
  207. {
  208.   if (this.datasource==null) this.makeemptyds();
  209.  
  210.   var anon=RDFService.GetAnonymousResource();
  211.   var node=new RDFNode();
  212.   node.Init(anon,this.datasource);
  213.   return node;
  214. }
  215.  
  216. RDFDataSource.prototype.getLiteral=
  217.   function (uri)
  218. {
  219.   if (this.datasource==null) this.makeemptyds();
  220.  
  221.   return new RDFLiteral(uri,this);
  222. }
  223.  
  224. RDFDataSource.prototype.refresh=
  225.   function (sync)
  226. {
  227.   try {
  228.     var ds=this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
  229.     ds.Refresh(sync);
  230.     return true;
  231.   }
  232.   catch (ex){
  233.     return false;
  234.   }
  235. }
  236.  
  237. RDFDataSource.prototype.save=
  238.   function ()
  239. {
  240.   try {
  241.     var ds=this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
  242.     ds.Flush();
  243.     return true;
  244.   }
  245.   catch (ex){
  246.     return false;
  247.   }
  248. }
  249.  
  250. RDFDataSource.prototype.copyAllToDataSource=
  251.   function (dsource2)
  252. {
  253.   if (this.datasource==null) this.makeemptyds();
  254.   if (dsource2.datasource==null) dsource2.makeemptyds();
  255.  
  256.   var dsource1=this.datasource;
  257.   dsource2=dsource2.datasource;
  258.  
  259.   var sourcelist=dsource1.GetAllResources();
  260.   while(sourcelist.hasMoreElements()){
  261.     var source=sourcelist.getNext();
  262.     var props=dsource1.ArcLabelsOut(source);
  263.     while(props.hasMoreElements()){
  264.       var prop=props.getNext();
  265.       prop=prop.QueryInterface(Components.interfaces.nsIRDFResource);
  266.       var target=dsource1.GetTarget(source,prop,true);
  267.       if (target!=null) dsource2.Assert(source,prop,target,true);
  268.     }
  269.   }
  270. }
  271.  
  272. RDFDataSource.prototype.deleteDescendents=
  273.   function (val)
  274. {
  275.   var node;
  276.   var dsource=this.datasource;
  277.  
  278.   if (dsource==null) return;
  279.  
  280.   if (typeof val == "string") node=RDFService.GetResource(val);
  281.   else node=val.source;
  282.  
  283.   this.deleteRecursiveH(dsource,node); // remove descendants
  284.  
  285. }
  286.  
  287. RDFDataSource.prototype.deleteRecursive=
  288.   function (val)
  289. {
  290.   var node;
  291.   var dsource=this.datasource;
  292.  
  293.   if (dsource==null) return;
  294.  
  295.   if (typeof val == "string") node=RDFService.GetResource(val);
  296.   else node=val.source;
  297.  
  298.   this.deleteRecursiveH(dsource,node); // remove descendants
  299.  
  300.   // remove the node itself
  301.   var props=dsource.ArcLabelsIn(node);
  302.   while(props.hasMoreElements()){
  303.     var prop=props.getNext();
  304.     var source=dsource.GetSource(prop,node,true);
  305.     dsource.Unassert(source,prop,node);
  306.   }
  307. }
  308.  
  309. RDFDataSource.prototype.deleteRecursiveH=
  310.   function (dsource,node)
  311. {
  312.   var props=dsource.ArcLabelsOut(node);
  313.   while(props.hasMoreElements()){
  314.     var prop=props.getNext();
  315.     var target=dsource.GetTarget(node,prop,true);
  316.     try {
  317.       target=target.QueryInterface(Components.interfaces.nsIRDFResource);
  318.       this.deleteRecursiveH(dsource,target);
  319.     }
  320.     catch (e){}
  321.     dsource.Unassert(node,prop,target)
  322.   }
  323. }
  324.  
  325. function RDFNode(uri,dsource)
  326. {
  327.   if (uri==null) this.source=null;
  328.   else this.source=RDFService.GetResource(uri);
  329.  
  330.   if (dsource==null) this.datasource=null;
  331.   else this.datasource=dsource.datasource;
  332.  
  333.   this.container=null;
  334. }
  335.  
  336. RDFNode.prototype.Init=
  337.   function (source,dsource)
  338. {
  339.   this.source=source;
  340.   this.datasource=dsource;
  341.   this.container=null;
  342. }
  343.  
  344. RDFNode.prototype.getValue=
  345.   function ()
  346. {
  347.   return this.source.Value;
  348. }
  349.  
  350. RDFNode.prototype.rlify=
  351.   function (val)
  352. {
  353.   var res=null;
  354.  
  355.   if (val!=null){
  356.     try {
  357.       val=val.QueryInterface(Components.interfaces.nsIRDFResource);
  358.       res=new RDFNode();
  359.       res.Init(val,this.datasource);
  360.     }
  361.     catch (ex){
  362.       try {
  363.         val=val.QueryInterface(Components.interfaces.nsIRDFLiteral);
  364.         res=new RDFLiteral();
  365.         res.Init(val,this.datasource);
  366.       }
  367.       catch (ex2){
  368.       }
  369.     }
  370.   }
  371.   return res;
  372. }
  373.  
  374. RDFNode.prototype.makeres=
  375.   function (val)
  376. {
  377.   if (typeof val == "string") return RDFService.GetResource(val);
  378.   else return val.source;
  379. }
  380.  
  381. RDFNode.prototype.makelit=
  382.   function (val)
  383. {
  384.   if (typeof val == "string") return RDFService.GetLiteral(val);
  385.   else return val.source;
  386. }
  387.  
  388. RDFNode.prototype.makecontain=
  389.   function ()
  390. {
  391.   if (this.container!=null) return true;
  392.  
  393.   var RDFContainer = '@mozilla.org/rdf/container;1';
  394.   RDFContainer = Components.classes[RDFContainer].createInstance();
  395.   RDFContainer = RDFContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
  396.  
  397.   try {
  398.     RDFContainer.Init(this.datasource,this.source);
  399.     this.container=RDFContainer;
  400.     return true;
  401.   }
  402.   catch (ex){
  403.     return false;
  404.   }
  405. }
  406.  
  407. RDFNode.prototype.addTarget=
  408.   function (prop,target)
  409. {
  410.   prop=this.makeres(prop);
  411.   target=this.makelit(target);
  412.   this.datasource.Assert(this.source,prop,target,true);
  413. }
  414.  
  415. RDFNode.prototype.addTargetOnce=
  416.   function (prop,target)
  417. {
  418.   prop=this.makeres(prop);
  419.   target=this.makelit(target);
  420.  
  421.   var oldtarget=this.datasource.GetTarget(this.source,prop,true);
  422.   if (oldtarget!=null){
  423.     this.datasource.Change(this.source,prop,oldtarget,target);
  424.   }
  425.   else {
  426.     this.datasource.Assert(this.source,prop,target,true);
  427.   }
  428. }
  429.  
  430. RDFNode.prototype.modifyTarget=
  431.   function (prop,oldtarget,newtarget)
  432. {
  433.   prop=this.makeres(prop);
  434.   oldtarget=this.makelit(oldtarget);
  435.   newtarget=this.makelit(newtarget);
  436.   this.datasource.Change(this.source,prop,oldtarget,newtarget);
  437. }
  438.  
  439. RDFNode.prototype.modifySource=
  440.   function (prop,oldsource,newsource)
  441. {
  442.   prop=this.makeres(prop);
  443.   oldsource=this.makeres(oldsource);
  444.   newsource=this.makeres(newsource);
  445.   this.datasource.Move(oldsource,newsource,prop,this.source);
  446. }
  447.  
  448. RDFNode.prototype.targetExists=
  449.   function (prop,target)
  450. {
  451.   prop=this.makeres(prop);
  452.   target=this.makelit(target);
  453.   return this.datasource.HasAssertion(this.source,prop,target,true);
  454. }
  455.  
  456. RDFNode.prototype.removeTarget=
  457.   function (prop,target)
  458. {
  459.   prop=this.makeres(prop);
  460.   target=this.makelit(target);
  461.   this.datasource.Unassert(this.source,prop,target);
  462. }
  463.  
  464. RDFNode.prototype.getProperties=
  465.   function ()
  466. {
  467.   return new RDFEnumerator(this.datasource.ArcLabelsOut(this.source),this.datasource);
  468. }
  469.  
  470. RDFNode.prototype.getInProperties=
  471.   function ()
  472. {
  473.   return new RDFEnumerator(this.datasource.ArcLabelsIn(this.source),this.datasource);
  474. }
  475.  
  476. RDFNode.prototype.propertyExists=
  477.   function (prop)
  478. {
  479.   prop=this.makeres(prop);
  480.   return this.datasource.hasArcOut(this.source,prop);
  481. }
  482.  
  483. RDFNode.prototype.inPropertyExists=
  484.   function (prop)
  485. {
  486.   prop=this.makeres(prop);
  487.   return this.datasource.hasArcIn(this.source,prop);
  488. }
  489.  
  490. RDFNode.prototype.getTarget=
  491.   function (prop)
  492. {
  493.   prop=this.makeres(prop);
  494.   return this.rlify(this.datasource.GetTarget(this.source,prop,true));
  495. }
  496.  
  497. RDFNode.prototype.getSource=
  498.   function (prop)
  499. {
  500.   prop=this.makeres(prop);
  501.   var src=this.datasource.GetSource(prop,this.source,true);
  502.   if (src==null) return null;
  503.   var res=new RDFNode();
  504.   res.Init(src,this.datasource);
  505.   return res;
  506. }
  507.  
  508. RDFNode.prototype.getTargets=
  509.   function (prop)
  510. {
  511.   prop=this.makeres(prop);
  512.   return new RDFEnumerator(
  513.     this.datasource.GetTargets(this.source,prop,true),this.datasource);
  514. }
  515.  
  516. RDFNode.prototype.getSources=
  517.   function (prop)
  518. {
  519.   prop=this.makeres(prop);
  520.   return new RDFEnumerator(
  521.     this.datasource.GetSources(prop,this.source,true),this.datasource);
  522. }
  523.  
  524. RDFNode.prototype.makeBag=
  525.   function ()
  526. {
  527.   this.container=RDFContainerUtilsService.MakeBag(this.datasource,this.source);
  528. }
  529.  
  530. RDFNode.prototype.makeSeq=
  531.   function ()
  532. {
  533.   this.container=RDFContainerUtilsService.MakeSeq(this.datasource,this.source);
  534. }
  535.  
  536. RDFNode.prototype.makeAlt=
  537.   function ()
  538. {
  539.   this.container=RDFContainerUtilsService.MakeAlt(this.datasource,this.source);
  540. }
  541.  
  542. RDFNode.prototype.isBag=
  543.   function ()
  544. {
  545.   return RDFContainerUtilsService.IsBag(this.datasource,this.source);
  546. }
  547.  
  548. RDFNode.prototype.isSeq=
  549.   function ()
  550. {
  551.   return RDFContainerUtilsService.IsSeq(this.datasource,this.source);
  552. }
  553.  
  554. RDFNode.prototype.isAlt=
  555.   function ()
  556. {
  557.   return RDFContainerUtilsService.IsAlt(this.datasource,this.source);
  558. }
  559.  
  560. RDFNode.prototype.isContainer=
  561.   function ()
  562. {
  563.   return RDFContainerUtilsService.IsContainer(this.datasource,this.source);
  564. }
  565.  
  566. RDFNode.prototype.getChildCount=
  567.   function ()
  568. {
  569.   if (this.makecontain()){
  570.     return this.container.GetCount();
  571.   }
  572.   return -1;
  573. }
  574.  
  575. RDFNode.prototype.getChildren=
  576.   function ()
  577. {
  578.   if (this.makecontain()){
  579.     return new RDFEnumerator(this.container.GetElements(),this.datasource);
  580.   }
  581.   else return null;
  582. }
  583.  
  584. RDFNode.prototype.addChild=
  585.   function (child,exists)
  586. {
  587.   if (this.makecontain()){
  588.     var childres=null;
  589.     if (typeof child == "string"){
  590.       childres=RDFService.GetResource(child);
  591.       child=new RDFNode();
  592.       child.Init(childres,this.datasource);
  593.     }
  594.     else childres=child.source;
  595.  
  596.     if (!exists && this.container.IndexOf(childres)>=0) return child;
  597.  
  598.     this.container.AppendElement(childres);
  599.     return child;
  600.   }
  601.   else return null;
  602. }
  603.  
  604. RDFNode.prototype.addChildAt=
  605.   function (child,idx)
  606. {
  607.   if (this.makecontain()){
  608.     var childres=null;
  609.     if (typeof child == "string"){
  610.       childres=RDFService.GetResource(child);
  611.       child=new RDFNode();
  612.       child.Init(childres,this.datasource);
  613.     }
  614.     else childres=child.source;
  615.     this.container.InsertElementAt(childres,idx,true);
  616.     return child;
  617.   }
  618.   else return null;
  619. }
  620.  
  621. RDFNode.prototype.removeChild=
  622.   function (child)
  623. {
  624.   if (this.makecontain()){
  625.     var childres=null;
  626.     if (typeof child == "string"){
  627.       childres=RDFService.GetResource(child);
  628.       child=new RDFNode();
  629.       child.Init(childres,this.datasource);
  630.     }
  631.     else childres=child.source;
  632.       childres=RDFService.GetResource(child);
  633.     this.container.RemoveElement(childres,true);
  634.     return child;
  635.   }
  636.   else return null;
  637. }
  638.  
  639. RDFNode.prototype.removeChildForReal=
  640.   function (aChild)
  641. {
  642.   if (this.makecontain()){
  643.     this.container.RemoveElement(aChild.source, true);
  644.  
  645.   }
  646.   else return null;
  647. }
  648.  
  649.  
  650. RDFNode.prototype.removeChildAt=
  651.   function (idx)
  652. {
  653.   if (this.makecontain()){
  654.     var childres=this.container.RemoveElementAt(idx,true);
  655.     return this.rlify(childres);
  656.   }
  657.   else return null;
  658. }
  659.  
  660. RDFNode.prototype.getChildIndex=
  661.   function (child)
  662. {
  663.   if (this.makecontain()){
  664.     return this.container.IndexOf(child.source);
  665.   }
  666.   else return -1;
  667. }
  668.  
  669. RDFNode.prototype.type="Node";
  670.  
  671.  
  672. function RDFLiteral(val,dsource)
  673. {
  674.   if (val==null) this.source=null;
  675.   else this.source=RDFService.GetLiteral(val);
  676.  
  677.   if (dsource==null) this.datasource=null;
  678.   else this.datasource=dsource.datasource;
  679. }
  680.  
  681. RDFLiteral.prototype.Init=
  682.   function (source,dsource)
  683. {
  684.   this.source=source;
  685.   this.datasource=dsource;
  686. }
  687.  
  688. RDFLiteral.prototype.getValue=
  689.   function ()
  690. {
  691.   return this.source.Value;
  692. }
  693.  
  694. RDFLiteral.prototype.makeres=
  695.   function (val)
  696. {
  697.   if (typeof val == "string") return RDFService.GetResource(val);
  698.   else return val.source;
  699. }
  700.  
  701. RDFLiteral.prototype.makelit=
  702.   function (val)
  703. {
  704.   if (typeof val == "string") return RDFService.GetLiteral(val);
  705.   else return val.source;
  706. }
  707.  
  708. RDFLiteral.prototype.modifySource=
  709.   function (prop,oldsource,newsource)
  710. {
  711.   prop=this.makeres(prop);
  712.   oldsource=this.makeres(oldsource);
  713.   newsource=this.makeres(newsource);
  714.   this.datasource.Move(oldsource,newsource,prop,this.source);
  715. }
  716.  
  717. RDFLiteral.prototype.getInProperties=
  718.   function (prop)
  719. {
  720.   return new RDFEnumerator(this.datasource.ArcLabelsIn(this.source),this.datasource);
  721. }
  722.  
  723. RDFLiteral.prototype.inPropertyExists=
  724.   function (prop)
  725. {
  726.   prop=this.makeres(prop);
  727.   return this.datasource.hasArcIn(this.source,prop);
  728. }
  729.  
  730. RDFLiteral.prototype.getSource=
  731.   function (prop)
  732. {
  733.   prop=this.makeres(prop);
  734.   var src=this.datasource.GetSource(prop,this.source,true);
  735.   if (src==null) return null;
  736.   var res=new RDFNode();
  737.   res.Init(src,this.datasource);
  738.   return res;
  739. }
  740.  
  741. RDFLiteral.prototype.getSources=
  742.   function (prop)
  743. {
  744.   prop=this.makeres(prop);
  745.   return new RDFEnumerator(
  746.     this.datasource.GetSources(prop,this.source,true),this.datasource);
  747. }
  748.  
  749. RDFLiteral.prototype.type="Literal";
  750.  
  751.  
  752. function RDFEnumerator(enumeration,dsource)
  753. {
  754.   this.enumeration=enumeration;
  755.   this.datasource=dsource;
  756. }
  757.  
  758. RDFEnumerator.prototype.hasMoreElements=
  759.   function ()
  760. {
  761.   return this.enumeration.hasMoreElements();
  762. }
  763.  
  764. RDFEnumerator.prototype.getNext=
  765.   function ()
  766. {
  767.   var res=null;
  768.   var val=this.enumeration.getNext();
  769.  
  770.   if (val!=null){
  771.     try {
  772.       val=val.QueryInterface(Components.interfaces.nsIRDFResource);
  773.       res=new RDFNode();
  774.       res.Init(val,this.datasource);
  775.     }
  776.     catch (ex){
  777.       try {
  778.         val=val.QueryInterface(Components.interfaces.nsIRDFLiteral);
  779.         res=new RDFLiteral();
  780.         res.Init(val,this.datasource);
  781.       }
  782.       catch (ex2){
  783.       }
  784.     }
  785.   }
  786.   return res;
  787. }
  788.  
  789.